<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page contentType="text/html; charset=UTF-8" %>

<%@ page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@ page import="model.Mesto"%>

<jsp:useBean id="mfromTown" class="model.Mesto" scope="session" />
<jsp:useBean id="mToTown" class="model.Mesto" scope="session" />

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Red voznje</title>
</head>
<body>
<h1>Red voznje</h1>

<form action="/admin" method="get">
<table>
		<tr>
		<td align="right">Od:</td>
		<td><select name="fromTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:if test="${empty mfromTown.sifra.id}">
					<option>${town.naziv}</option>
				</c:if>
				<c:if test="${not empty mfromTown.sifra.id}">
					<c:if test="${mfromTown.sifra.id == town.sifra.id}">
						<option selected="selected">${town.naziv}</option>
					</c:if>
					<c:if test="${mfromTown.sifra.id != town.sifra.id}">
						<option>${town.naziv}</option>
					</c:if>
				</c:if>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td align="right">Do:</td>
		<td><select name="toTown">
			<c:forEach var="town" items="${sessionScope.allTowns}">
				<c:if test="${empty mToTown.sifra.id}">
					<option>${town.naziv}</option>
				</c:if>
				<c:if test="${not empty mToTown.sifra.id}">
					<c:if test="${mToTown.sifra.id == town.sifra.id}">
						<option selected="selected">${town.naziv}</option>
					</c:if>
					<c:if test="${mToTown.sifra.id != town.sifra.id}">
						<option>${town.naziv}</option>
					</c:if>
				</c:if>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td><input name="showTrip" type="hidden" value="true"></td>
		<td align="center"><input type="submit" value="Prikazi"></td>
	</tr>
</table>
</form>

<table border="1">
	<tr bgcolor="lightGrey">
		<td>ID</td>
		<td>Od</td>
		<td>Do</td>
		<td>Prevoznik</td>
		<td>Polazak</td>
		<td>Dolazak</td>
		<td>Cena</td>
		<td>Povlastice</td>
		<td>Akcija</td>
	</tr>

	<c:forEach var="trip" items="${sessionScope.allTrips}" varStatus="rowCounter">
		<tr>
			<td><c:out value="${rowCounter.count}" /></td>
			<td><c:out value="${trip.mestoOd.naziv}" /></td>
			<td><c:out value="${trip.mestoDo.naziv}" /></td>
			<td><a href="/admin?showCarrier=true&ID=${trip.prevoznik.sifra.id}">${trip.prevoznik.naziv}</a></td>
			<td><fmt:formatDate pattern="hh:mm" value="${trip.polazak}" /></td>
			<td><fmt:formatDate pattern="hh:mm" value="${trip.dolazak}" /></td>
			<td><c:out value="${trip.cena}" /></td>
			<td><c:forEach var="povl" items="${trip.povlastica}">
				<a href="/admin?showBenefit=true&ID=${povl.sifra.id}">${povl.naziv}</a>&nbsp;
			</c:forEach></td>
			<td><a href="/admin?showTripData=true&ID=${trip.sifra.id}">Pregled</a>
			<a href="/admin?changeTrip=true&ID=${trip.sifra.id}">Izmena</a> <a
				href="/admin?deleteTrip=true&ID=${trip.sifra.id}">Brisanje</a></td>
		</tr>
	</c:forEach>
</table>
<br />
<br />

<p><a href="/admin?addNewTrip=true">Nova linija</a> <br>
<a href="/admin?addNewCarrier=true">Novi prevoznik</a> <br>
<a href="/admin?pickCarrier=true">Prikazi prevoznika</a> <br>

<p><a href="/logIn?logOff=true">Odjava</a></p>
</body>
</html>
